package com.hdq.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hdq.mapper.ImageClassMapper;
import com.hdq.result.PageResult;
import com.hdq.service.ImageClassService;
import com.hdq.utils.AliOssUtil;
import dto.ImageClassAddDTO;
import dto.ImageClassEditDTO;
import entity.ImageClass;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImageClassServiceImpl implements ImageClassService {

    @Autowired
    private ImageClassMapper imageClassMapper;

    @Autowired
    private AliOssUtil aliOssUtil;

    @Override
    public ImageClass insert(ImageClassAddDTO imageClassAddDTO) {
        ImageClass imageClass = ImageClass.builder().name(imageClassAddDTO.getName()).order(imageClassAddDTO.getOrder()).build();

        imageClassMapper.insert(imageClass);

        return imageClass;

    }

    @Override
    public PageResult selectPictureCategoryByPage(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);

        List<ImageClass> imageClasses = imageClassMapper.selectPictureCategoryByPage();

        PageInfo<ImageClass> imageClassPageInfo = new PageInfo<>(imageClasses);

        return new PageResult(imageClassPageInfo.getTotal(),imageClassPageInfo.getList());
    }


    @Override
    public List<ImageClass> selectPictureCategory() {
        return imageClassMapper.selectPictureCategory();
    }




    @Override
    public void update(ImageClassEditDTO imageClassEditDTO) {
        ImageClass imageClass = new ImageClass();
        BeanUtils.copyProperties(imageClassEditDTO,imageClass);
        imageClassMapper.update(imageClass);
    }




    @Override
    public void deleteImageCategory(Integer id) {
        imageClassMapper.deleteImageCategory(id);
    }





}
